package com.heima.admin.job;

import com.heima.admin.service.WemediaNewsAutoScanService;
import com.heima.feigns.wemedia.WemediaFeign;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description:
 * @Version: V1.0
 */
@Component
@Slf4j
public class WeMediaNewsAutoScanJob {

    @Autowired
    WemediaFeign wemediaFeign;

    @Autowired
    WemediaNewsAutoScanService newsAutoScanService;

    // bug：方法参数问题
    @XxlJob("wemediaAutoScanJob")
    public ReturnT<String> autoScanJob(String param) {
        log.info("**************XXL-JOB autoScanJob任务开始执行**************");

        List<Integer> wmNewsIds = wemediaFeign.findRelease();

        if (wmNewsIds != null && wmNewsIds.size() > 0) {

            for (Integer wmNewsId : wmNewsIds) {
                newsAutoScanService.autoScanByMediaNewsId(wmNewsId);
            }

            log.info("**************XXL-JOB autoScanJob任务执行完成**************");
        }

        return ReturnT.SUCCESS;
    }

}
